package com.wdb.user.repository.support;

import com.wdb.common.constant.Constant;
import com.wdb.common.repository.support.CrudRepositorySupport;
import com.wdb.domain.user.entity.UserInfoPin;
import com.wdb.user.repository.UserInfoPinRepository;
import com.wdb.user.repository.mapper.UserInfoPinMapper;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Repository
public class UserInfoPinRepositorySupport extends CrudRepositorySupport<UserInfoPinMapper, UserInfoPin> implements UserInfoPinRepository {

    @Override
    public UserInfoPin findByMobile(String mobile) {

        Example example = new Example(entityClass);
        example.createCriteria()
                .andEqualTo("mobile", mobile)
                .andEqualTo("deleted", Constant.N);

        List<UserInfoPin> users = mapper.selectByExample(example);

        if (!CollectionUtils.isEmpty(users)) {
            return users.get(0);
        }
        return null;
    }

}
